# coding=gbk
"""
Created on 

@author: 

@about:

"""

import time
from itertools import count, islice
from multiprocessing.dummy import Pool as ThreadPool


def f(a, b):
    time.sleep(0.1)
    return a + b


def f_analyze(x):
    return f(x[0], x[1])


def MonThread():
    time_1 = time.time()
    result = []
    for i in islice(count(), 0, 10):
        result.append(f(1, 1))
    time_2 = time.time()
    print "MonThread:", time_2 - time_1


def MultiThread():
    time_1 = time.time()
    pool = ThreadPool(4)
    result = pool.map(f_analyze, [(1, 1) for i in islice(count(), 0, 10)])
    pool.close()
    pool.join()
    time_2 = time.time()
    print  "MultiThread:", time_2 - time_1


if __name__ == '__main__':
    print "**************start**************\n\n"

    MonThread()
    MultiThread()

    print "\n\n**************end**************"
